<template>
  <div class="app-container">
    <!-- <img src="@/assets/img/demo.png" alt=""> -->
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane v-if="authorityHandle(5)" label="公告" name="notice" />
      <el-tab-pane v-if="authorityHandle(177)" label="站内信" name="message" />
      <el-tab-pane v-if="authorityHandle(178)" label="自定义站内信" name="custommessage" />
      <div class="tab-content">
        <keep-alive>
          <!-- https://cn.vuejs.org/v2/guide/components.html#%E5%8A%A8%E6%80%81%E7%BB%84%E4%BB%B6 -->
          <component :is="curTabcompnents[activeName]" />
        </keep-alive>
      </div>
    </el-tabs>
  </div>
</template>

<script>

import NoticeTabPane from './components/NoticeTabPane'
import MessageTabPane from './components/MessageTabPane'
import CustomMessageTabPane from './components/CustomMessageTabPane'

export default {
  name: 'Tab',
  components: { NoticeTabPane, MessageTabPane, CustomMessageTabPane },
  data() {
    return {
      activeName: 'notice',
      curTabcompnents: {
        'notice': 'NoticeTabPane',
        'message': 'MessageTabPane',
        'custommessage': 'CustomMessageTabPane'
      }

    }
  },
  watch: {
    activeName(val) {
      this.$router.push(`${this.$route.path}?tab=${val}`)
    }
  },
  created() {
    // init the default selected tab
    const tab = this.$route.query.tab
    if (tab) {
      this.activeName = tab
    } else {
      if (this.authorityHandle(5)) {
        this.activeName = 'notice'
      } else if (this.authorityHandle(177)) {
        this.activeName = 'message'
      } else if (this.authorityHandle(178)) {
        this.activeName = 'custommessage'
      }
    }
  },
  methods: {
    handleClick(tab) {
      this.activeName = tab.name
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 0px;
}
</style>
